Character Set of C
Character set of a language is set of all the symbols used to write a program in that language.
C TOKENS
In a C program the smallest individual units are known as C token.
C has six type of tokens.
Keywords
Keywords are those words whose meaning already has been explained to the C compiler
Meanings of Keywords cannot be changed.
Keywords cannot be used as variable names
Keywords are also called Reserved Words.
Identifiers
Identifiers refers to the names of variables, functions and arrays.
These are user-defined names and consist of a sequence of letters and digits.
What is Data Type?
Data Type is a classification that specifies which type of value a variable has and what type of mathemetical,
relation or logical opertions can be applied to it without causing an error.
A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
C support three classes of Data Type
Primary Data Type These are main Data Type, which are made by the C programmers.
These data types are already stored in the header files.
Size & Range of Data Types on a 16-bit Machine
Type |
Size |
Range |
char or signed char |
8 |
-128 to 127 |
unsigned char |
8 |
0 to 255 |
int or signed int |
16 |
-32,768 to 32,767 |
unsigned int |
16 |
0 to 65,535 |
short int or
signed short int |
8 |
-128 to 127 |
unsigned short int |
8 |
0 to 255 |
long int or
signed long int |
32 |
-2,147,483,648 to
2,147,483,647 |
unsigned long int |
32 |
0 to 4,294,967,295 |
float |
32 |
3.4E-38 to
3.4E+38 |
double |
64 |
1.7E-308 to 1.7E+308 |
long double |
80 |
3.4E-4932 to 1.1E+4932 |
Integer Type
- Integers are whole numbers with a range of values supported by a particular machine.
- Generally, integers occupy one word of storage and since the word sizes of machines vary the
size of an integer that can be stored depends on the computer.
Floating Point Type
- Floating point (or real) numbers are stored in 32 bit (on all 16 bit and 32 bit machine, 6 digits of precision.
- Floating point numbers are defined in C by the keyword float.
- A float occupies 4 bytes in memory and can range from -3.4e38 to +3.4e.38
- If this is insufficient, then C offers a double data type that occupies 8 byte in memory and has a range from -1.7e308 to +1.7e308.
Void Type
- The void type has no value.
- This is usually used to specify the type of functions.
- This type of a function is said to be void when it does not return any value to the calling function.
- It can also play the role of a generic type, meaning that it can represent any of the other standard types.
Character Type
- A single character can be defined as a character (char) type data.
- Character are usually stored in 8 bits (one byte) of internal storage
- The qualifier signed or unsigned may be explicitly applied to char.
Constant
In C programming constants refers to fixed value that do not change during the execution of a program.
Integer Constants
An integer constants refers to a sequence of digits.
Example:
426
-8000
+782
Real Constants
Numbers containing fractional parts like 17.582 are called Real Constants.
Real constant are often called Floating Point Constants
The real constants could be written in two forms --
- Fractorial form and
- Exponential form
Example:
+325.34
426.0
-32.67
Example:
+3.2e-5
4.1e8
-0.2E+3
Single Character Constants
A single character constant (or simply character constant) contains a single character enclosed within a pair of single quote ('') marks.
Example:
'5'
'X'
'.'
''
Note
The character constant '5' is not the same as the Number 5.
The maximum length of a characer constant can be 1 character.
String Constants
A string constants is a sequence of characters enclosed in double quotes (" ").
The characters may be letters, numbers, special characters and blank space.
Example:
"Hello"
"1987"
"well done
Note
A character constant (e.g. 'X' is not equivalent to a single character string constant (e.g. "X").
A single character string does not have an equivalent integer value while a character constant has an integer value .
Backslash Character Constant
C support some special backslash character constant that are used in output functions.
Note
Each one of backslash character represents one character, although they consist of two character. These character combinations are known as escape sequences.
A single character string does not have an equivalent integer value while a character constant has an integer value .
Variable
A variable is a data name that may be used to store a data value.
Variables are named storage locations whose value can be manipulated during the execution of program.
An entity that may vary during program execution is called a variable.
Declaration of Variable
After designing suitable variable names, we must declare them to the compiler.
The declaration of variable must be done before they are used in the program.
Declaration does two things:
- ] It tells the compiler what the variable name is.
- ] It specifies what type of data the variable will hold
Primary Type Decleration
User-defined Type Declaration
type-definition allows users to define an integer that would represent an existing data type. The user-defined data type identifiers can later be used to declare variables.
The main advantage of typedef is that we can create meaningful data type names for increasing the readability of the program.
where :
type |
refers to an existing data type
The existing data type may belong to any class of type including the user defined ones. |
identifiers
|
refers to the 'new' name given to the datatype. The existing data type may belong to any class of type,
including the user-defined ones.
|
Remember that the new type is 'new' only in name, but not the data type typedef cannot create a new type.
|
Example
|
typedef int units;
typedef float marks;
units batch1, batch2;
marks name1[50], name2[50];
|
/*Here, units symbolizes int and marks symbolizes float
They can later used to declare variables as follows.*/
|
Assigning Value to Variable
value can be assigned to variable using the assignment operator ' = ' as follows :
Assigning values to a variable at the time the variable is declared :